<?php
/**
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/27
 * Time: 17:58
 */
class DeletetizhengbatchdataController extends Yaf_Controller_Abstract
{
    public function IndexAction()
    {
        $request = $this->getRequest();
        $batch_id = $request->getPost("batch_id","");
        $yiyuan_id = $request->getPost("yiyuan_id","");
        $zhuyuan_id = $request->getPost("zhuyuan_id",0);

        //医院id判断
        if($yiyuan_id === "")
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }

        if($batch_id === "")
        {
            Utility::apiJsonError(20028, 'Batch ID为空');
        }
        elseif(!ctype_digit("$batch_id"))
        {
            Utility::apiJsonError(20027, 'Batch必须是整型');
        }

       
        $sql = DB::update('zhuyuan_tizheng')
            ->set(array('state'  => 0, 'modify_time'=> date('Y-m-d H:i:s',time())))
            ->where('batch_id','=', $batch_id)
            ->and_where('yiyuan_id', '=', $yiyuan_id)
            ->and_where('state', '=', 1);
            if($zhuyuan_id)
            {
                $sql->and_where('zhuyuan_id', '=', $zhuyuan_id);
            }
            $res = $sql->execute();
       // $sql = "update zhuyuan_tizheng set state=0,modify_time ='".date('Y-m-d H:i:s',time())."' where batch_id='".trim($batch_id)."' and state=1";
        $sql_act = DB::update('zhuyuan_tizheng_batch')
            ->set(array('state'  => 0))
            ->where('batch_id','=', $batch_id)
            ->and_where('yiyuan_id', '=', $yiyuan_id)
            ->and_where('state', '=', 1)->execute();
        //M()->execute('update zhuyuan_tizheng_batch set state=0 where batch_id='.$batch_id.' and state=1');
        if($sql_act)
        {
            $statr['state'] =1;
        }else{
            $statr['state'] =0;
        }
        $statr['error'] = 200;
        $statr['msg'] = "";
        Utility::apiJsonResultExtends($statr);
    }
}